package org.inspursc.s0517.health.common.converter;

import org.inspursc.s0517.health.common.dto.SysUserDTO;
import org.inspursc.s0517.health.common.entity.SysUser;
import org.inspursc.s0517.health.common.enums.UserTypeEnum;
import org.inspursc.s0517.health.common.form.UserForm;
import org.inspursc.s0517.health.common.vo.SysUserVO;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;


public class UserConverter2SysUserDTO {

    public static SysUserDTO converter(UserForm userForm) {
        SysUserDTO sysUserDTO = new SysUserDTO();
        BeanUtils.copyProperties(userForm, sysUserDTO);
        if(userForm.getUserType()!=null) {
            sysUserDTO.setUserType(userForm.getUserType());
        }
        return sysUserDTO;
    }

    public static SysUserDTO converter(SysUser sysUser) {
        SysUserDTO sysUserDTO = new SysUserDTO();
        BeanUtils.copyProperties(sysUser, sysUserDTO);
        sysUserDTO.setUserType(UserTypeEnum.valueOf(sysUser.getUserType()));
        return sysUserDTO;
    }

    public static SysUserVO converter2VO(SysUser sysUser) {
        SysUserVO sysUserVO = new SysUserVO();
        BeanUtils.copyProperties(sysUser, sysUserVO);
        return sysUserVO;
    }

    public static List<SysUserVO> converter2VO(List<SysUser> sysUserList) {
        return sysUserList.stream().map(e -> converter2VO(e)).collect(Collectors.toList());
    }


    public static SysUser converter(SysUserDTO userDTO) {
        SysUser sysUser = new SysUser();
        BeanUtils.copyProperties(userDTO, sysUser);
        if(userDTO.getUserType()!=null) {
            sysUser.setUserType(userDTO.getUserType().getCode());
        }
        return sysUser;
    }

    public static List<SysUserDTO> converter(List<SysUser> sysUserList) {
        return sysUserList.stream().map(e -> converter(e)).collect(Collectors.toList());
    }


}
